set(LIVE555_URL http://www.live555.com/liveMedia/public/live555-latest.tar.gz CACHE STRING "live555 url")
set(LIVE555_CFLAGS -DBSD=1 -DSOCKLEN_T=socklen_t -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -DALLOW_RTSP_SERVER_PORT_REUSE=1 -DNO_STD_LIB=1 CACHE STRING "live555 CFGLAGS")

if (WITH_SSL)
  find_package(OpenSSL QUIET)
endif()

set(LIVE ${CMAKE_BINARY_DIR}/live)
set(LIVE555_INC ${LIVE}/groupsock/include ${LIVE}/liveMedia/include ${LIVE}/UsageEnvironment/include ${LIVE}/BasicUsageEnvironment/include)
if (NOT EXISTS ${LIVE})
	file (DOWNLOAD ${LIVE555_URL} ${CMAKE_BINARY_DIR}/live555-latest.tar.gz )
	EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E tar xvf ${CMAKE_BINARY_DIR}/live555-latest.tar.gz  RESULT_VARIABLE unpack_result)
	if(NOT unpack_result STREQUAL "0")
		message(FATAL_ERROR "Fetching and compiling live555 failed!")
	endif()
endif()
FILE(GLOB LIVE555_FILES ${LIVE}/groupsock/*.c* ${LIVE}/liveMedia/*.c* ${LIVE}/UsageEnvironment/*.c* ${LIVE}/BasicUsageEnvironment/*.c*)
FILE(GLOB LIVE555_INC_FILES ${LIVE}/groupsock/*.h* ${LIVE}/liveMedia/*.h* ${LIVE}/UsageEnvironment/*.h* ${LIVE}/BasicUsageEnvironment/*.h*)
if (NOT OpenSSL_FOUND)
	set(LIVE555_CFLAGS ${LIVE555_CFLAGS} -DNO_OPENSSL=1)
endif()
